CREATE PROCEDURE spResultSet1 
  DYNAMIC RESULT SETS 1
BEGIN
  DECLARE cur1 CURSOR WITH RETURN FOR
    SELECT 'A', 'A1' FROM src LIMIT 3;
  OPEN cur1;
END;  
  
CREATE PROCEDURE spResultSet2
  DYNAMIC RESULT SETS 2
BEGIN
  DECLARE cur1 CURSOR WITH RETURN FOR
    SELECT 'B', 'B1' FROM src LIMIT 5;
  DECLARE cur2 CURSOR WITH RETURN FOR
    SELECT 'C', 'C1' FROM src LIMIT 7;
  OPEN cur1;
  OPEN cur2;
END;

DECLARE v1 VARCHAR(10);
DECLARE v2 VARCHAR(10);
DECLARE loc1 RESULT_SET_LOCATOR VARYING;
DECLARE loc2 RESULT_SET_LOCATOR VARYING;

CALL spResultSet1;

ASSOCIATE RESULT SET LOCATOR (loc1) WITH PROCEDURE spResultSet1;
ALLOCATE c1 CURSOR FOR RESULT SET loc1;

FETCH c1 INTO v1, v2;
WHILE (SQLCODE = 0)
DO
  PRINT v1 || ' - ' || v2;
  FETCH c1 INTO v1, v2;
END WHILE;
CLOSE c1;

CALL spResultSet2;

ASSOCIATE RESULT SET LOCATOR (loc1, loc2) WITH PROCEDURE spResultSet2;
ALLOCATE c2 CURSOR FOR RESULT SET loc1;

FETCH c2 INTO v1, v2;
WHILE (SQLCODE = 0)
DO
  PRINT v1 || ' - ' || v2;
  FETCH c2 INTO v1, v2;
END WHILE;
CLOSE c2;

ALLOCATE c3 CURSOR FOR RESULT SET loc2;

FETCH c3 INTO v1, v2;
WHILE (SQLCODE = 0)
DO
  PRINT v1 || ' - ' || v2;
  FETCH c3 INTO v1, v2;
END WHILE;
CLOSE c3;
